﻿using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Text.RegularExpressions;
using HQLAddin.Highlighting.Classificators.BaseClass;
using HQLAddin.Highlighting.Formatters;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;

namespace HQLAddin.Highlighting.Classificators
{
	[Export(typeof(IClassifierProvider))]
	[ContentType("xml")]
	internal sealed class ParameterClassifierProvider : IClassifierProvider
	{
		[Import]
		private IClassificationTypeRegistryService classificationRegistry;

		#region IClassifierProvider Members

		public IClassifier GetClassifier(ITextBuffer textBuffer)
		{

			return textBuffer
				.Properties
				.GetOrCreateSingletonProperty(() => new ParameterClassifier(classificationRegistry));
		}

		#endregion
	}

	internal class ParameterClassifier : RegexBasedClassifier
	{
		public ParameterClassifier(IClassificationTypeRegistryService classificationRegistry) 
			: base(classificationRegistry)
		{
		}

		public override string FormatterName
		{
			get { return ParameterFormat.Name; }
		}

		public override IEnumerable<Regex> Regexs
		{
			get
			{
				yield return new Regex(@"(\:[A-Za-z][A-Za-z0-9]*)");
				yield return new Regex(@"\?");
			}
		}
	}
}